package com.ibangnuo.manage.service.wxpay.impl;

import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;
import com.ibangnuo.manage.service.wxpay.WxpayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import java.io.*;


/**
 * @Author: wwy
 * @Date: 2020-01-17 9:51
 */
@Component
public class WxpayConfigImpl extends WXPayConfig {
    private static Logger LOGGER = LoggerFactory.getLogger(WxpayService.class);
    @Value("${wx.app_id}")
    private String appid;
    @Value("${wx.key}")
    private String key;
    @Value("${wx.mch_id}")
    private String mchID;


    @Override
    public String getAppID() {
        return this.appid;
    }

    @Override
    public String getMchID() {
        return this.mchID;
    }

    @Override
    public String getKey() {
        return this.key;
    }

    @Override
    public InputStream getCertStream() {
        ClassPathResource classPathResource = new ClassPathResource("apiclient_cert.pl2");
        InputStream inputStream = null;
        try {
            inputStream = classPathResource.getInputStream();
        } catch (IOException e) {
            LOGGER.error("读取证书文件错误", e.getMessage());
        }

        return inputStream;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        return new IWXPayDomainImpl();
    }


}
